<template>
  <view>
    <view class="bodytime">
      <u-radio-group
        v-model="radiovalue1"
        placement="column"
        icon-placement="right"
      >
        <u-radio
          :customStyle="{ marginBottom: '8px' }"
          v-for="(item, index) in times"
          :key="index"
          :label="item.detail"
          :name="item.detail"
          @change="radioChange(item)"
        >
        </u-radio>
      </u-radio-group>
    </view>
    <view class="footer">
      <u-button type="error" @click="funhuei()" text="确认"></u-button>
    </view>
  </view>
</template>

<script>
import { GetUserMsgCfg } from "@/public/Api/update.js";
import { setValue, getValue } from "@/public/storeage/index.js";
export default {
  data() {
    return {
      index: 0,
      shows: true,
      times: [
        {
          id: 0,
          time: "300",
          detail: "默认",
          shows: true,
        },
        {
          id: 1,
          time: "600",
          detail: "10分钟",
          shows: false,
        },
        {
          id: 2,
          time: "1800",
          detail: "30分钟",
          shows: false,
        },
        {
          id: 3,
          time: "3600",
          detail: "1小时",
          shows: false,
        },
      ],
      radiovalue1: "",
      tis: {},
    };
  },
  onLoad() {
    this.GetUserMsgCfg();
  },
  methods: {
    radioChange(n) {
      this.tis = n;
      console.log("radioChange", this.tis);
    },
    funhuei() {
      uni.$emit("times", this.tis);
      uni.navigateBack();
    },
    async GetUserMsgCfg() {
      var userId = getValue("id");
      try {
        const { data: res } = await GetUserMsgCfg({
          userId,
        });
        if (res.result.ttsInterval == 300) {
          this.radiovalue1 = "默认";
        } else if (res.result.ttsInterval == 600) {
          this.radiovalue1 = "10分钟";
        } else if (res.result.ttsInterval == 1800) {
          this.radiovalue1 = "30分钟";
        } else if (res.result.ttsInterval == 3600) {
          this.radiovalue1 = "1小时";
        }
      } catch (e) {}
    },
  },
};
</script>

<style lang="scss">
.bodytime {
  width: 92%;
  margin: 30upx auto;
  .u-radio {
    padding: 20upx 0;
    border-bottom: 1px solid #e8e8e8;
  }
}
.footer {
  width: 436upx;
  color: #fff;
  text-align: center;
  position: fixed;
  bottom: 60upx;
  left: 20%;
}
</style>
